package com.PAT.practice02;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/02/15/23:50
 * @Description:
 * @Target:
 */
public class 判断题 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ss1 = in.nextLine();
        String[] s = ss1.split(" ");
        int N = Integer.valueOf(s[0]);  // 学生人数
        int M = Integer.valueOf(s[1]);  // 判断题数量

        String score = in.nextLine();
        String correct = in.nextLine();

        String[] scores = score.split(" ");
        String[] corrects = correct.split(" ");

        int[] SumScores = new int[N];
        int count = 0;
        for (int i = 0; i < N; i++) {
            String tempString = in.nextLine();
            String[] s1 = tempString.split(" ");
            for (int j = 0; j < s1.length; j++) {
                if (s1[j].equals(corrects[j])){
                    count+=Integer.valueOf(scores[j]);
                }
            }
            SumScores[i] = count;
            count = 0;
        }


        for (int sumScore : SumScores) {
            System.out.println(sumScore);
        }


    }
}
